package com.momoauth.api_client.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.momoauth.api_client.entity.Groups;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface GroupsMapper extends BaseMapper<Groups> {

    /**
     * 查询群组列表
     * @return
     */
    @Select("SELECT groups.groupId,groups.groupName,groups.`status`,groups.createTime," +
            "(SELECT COUNT(1) FROM user_group WHERE group_id = groupId) AS groupUseNum " +
            "FROM `groups` ${ew.customSqlSegment}")
    List<Groups> getGroupList(Page<Groups> page, @Param(Constants.WRAPPER) QueryWrapper wrapper);

    /**
     * 删除群组
     * @param groupId
     * @return
     */
    @Update("UPDATE `groups` SET isDelete = 1 WHERE groupId = #{groupId}")
    Integer deleteGroupById(Long groupId);
}
